Skip to content

feat: Add support for Timestamp data type #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 16, 2025

Conversation

mgrazianoc
Copy link
Contributor

@mgrazianoc mgrazianoc commented Jun 10, 2025

Rationale for this change

Currently, the Swift implementation of Arrow does not support Timestamp, although they are available in the base C interface. This PR attempts to add its support by following the current implemented design pattern.

What changes are included in this PR?

  1. TimestampArray with some basic formatting utilities
  2. TimestampArrayBuilder
  3. Timestamp alias
  4. ArrowTimestampUnit, which includes extensively all the variants (seconds, milliseconds, microseconds and nanoseconds)
  5. ArrowTypeTimestamp from base Arrow
  6. ArrowType support for timestamp
  7. ArrowWriterHelper support for timestamp
  8. fromProto support for timestamp

It properly handles the presence or absence of timezone.

Are these changes tested?

Tests are included in both ArrayTests.swift and CDataTests.swift.

Are there any user-facing changes?

Yes - users can now work with Timestamp data types in Swift Arrow implementations. This is additive and doesn't break existing functionality.

Closes #32.

@kou kou requested a review from Copilot June 12, 2025 01:49
@kou
Copy link
Member

kou commented Jun 12, 2025

@abandy You may want to take a look at this too.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for the Timestamp data type in Swift Arrow by introducing new types, builders, and helper functions for formatting and serialization/deserialization. Key changes include:

  • Implementing TimestampArray, ArrowTypeTimestamp, and associated formatting utilities.
  • Extending builder and reader/writer helpers to recognize and handle Timestamp.
  • Adding comprehensive tests for Timestamp functionality in both CData and Array test suites.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Arrow/Tests/ArrowTests/CDataTests.swift Added tests for Timestamp fields with different units and timezone configurations.
Arrow/Tests/ArrowTests/ArrayTests.swift Introduced testTimestampArray covering various Timestamp units and formatting options.
Arrow/Sources/Arrow/ProtoUtil.swift Added Timestamp case handling for protobuffer conversion.
Arrow/Sources/Arrow/ArrowWriterHelper.swift Extended writer helper to include Timestamp serialization logic.
Arrow/Sources/Arrow/ArrowType.swift Introduced Timestamp alias, ArrowTypeTimestamp, and updated type-related functions.
Arrow/Sources/Arrow/ArrowReaderHelper.swift Added Timestamp support in array holder creation and type discovery.
Arrow/Sources/Arrow/ArrowArrayBuilder.swift Added TimestampArrayBuilder and integrated it into the builder registry.
Arrow/Sources/Arrow/ArrowArray.swift Added TimestampArray implementation with formatting utilities for date conversion.
Comments suppressed due to low confidence (1)

Arrow/Tests/ArrowTests/CDataTests.swift:47

  • [nitpick] Consider using more descriptive field names for Timestamp columns (e.g., 'colTimestampNanoseconds' instead of 'colTimestamptsn') to improve clarity in tests.
.addField("colTimestamptsn", type: ArrowTypeTimestamp(.nanoseconds), isNullable: false)

Comment on lines 266 to 274
let formatter = DateFormatter()
formatter.dateFormat = options.dateFormat
formatter.locale = options.locale

if options.includeTimezone, let timezone = timestampType.timezone {
formatter.timeZone = TimeZone(identifier: timezone)
}

return formatter.string(from: date)
Copy link
Preview

Copilot AI Jun 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new DateFormatter for each call of formattedDate(at:) may impact performance in tight loops; consider caching a formatter instance if possible.

Suggested change
let formatter = DateFormatter()
formatter.dateFormat = options.dateFormat
formatter.locale = options.locale
if options.includeTimezone, let timezone = timestampType.timezone {
formatter.timeZone = TimeZone(identifier: timezone)
}
return formatter.string(from: date)
if cachedFormatter == nil || cachedOptions != options {
let formatter = DateFormatter()
formatter.dateFormat = options.dateFormat
formatter.locale = options.locale
if options.includeTimezone, let timezone = timestampType.timezone {
formatter.timeZone = TimeZone(identifier: timezone)
}
cachedFormatter = formatter
cachedOptions = options
}
return cachedFormatter?.string(from: date)

Copilot uses AI. Check for mistakes.

@kou
Copy link
Member

kou commented Jun 12, 2025

Could you fix lint error?

You can use nice pre-commit run --show-diff-on-failure --color=always --all-files for it.

@kou
Copy link
Member

kou commented Jun 12, 2025

FYI: You can check CI results on your fork by enabling GitHub Actions on your fork.

Copy link
Contributor

@abandy abandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@mgrazianoc
Copy link
Contributor Author

mgrazianoc commented Jun 13, 2025

I've fixed linters by using the pre-commit suggestion, and reviewed the Copilot AI suggestion.

@kou kou changed the title GH-32: Add support for Timestamp data type #46753 feat: Add support for Timestamp data type Jun 16, 2025
Copy link
Member

@kou kou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@kou kou merged commit 476d1c0 into apache:main Jun 16, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Swift] Add support for Timestamp data type
3 participants